"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  data() {
    return {
      userphone: "",
      password: "",
      token: ""
    };
  },
  methods: {
    handleLogin() {
      if (this.userphone === "" || this.password === "") {
        common_vendor.index.showToast({
          title: "用户名或密码不能为空",
          icon: "none"
        });
        return;
      }
      const loginData = {
        userphone: this.userphone,
        password: this.password
      };
      common_vendor.index.request({
        url: "http://106.15.182.86:9099/api/login",
        method: "POST",
        data: loginData,
        header: {
          // 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; PCLM10 Build/PQ3B.190801.001010846; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36 uni-app Html5Plus/1.0 (Immersed/24.0)',
          "Content-Type": "application/json",
          "Host": "106.15.182.86:9099",
          "Connection": "Keep-Alive",
          "Accept-Encoding": "gzip"
        },
        success: (res) => {
          console.log("Response:", res);
          console.log("Before reLaunch");
          if (res.data && res.data.code === 200) {
            const token = res.data.token;
            common_vendor.index.setStorageSync("token", token);
            console.log(token);
            common_vendor.index.reLaunch({
              url: "/pages/index/index"
            });
          } else {
            console.log("Login failed:", res.data.message);
            common_vendor.index.showToast({
              title: res.data.message || "登录失败，请检查您的用户名和密码",
              icon: "none"
            });
          }
        },
        fail: (err) => {
          console.error("Login request failed:", err);
          common_vendor.index.showToast({
            title: "网络请求失败，请稍后再试",
            icon: "none"
          });
        }
      });
    },
    handleRegister() {
      common_vendor.index.navigateTo({
        url: "/pages/regist/regist"
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: $data.userphone,
    b: common_vendor.o(($event) => $data.userphone = $event.detail.value),
    c: $data.password,
    d: common_vendor.o(($event) => $data.password = $event.detail.value),
    e: common_vendor.o((...args) => $options.handleLogin && $options.handleLogin(...args)),
    f: common_vendor.o((...args) => $options.handleRegister && $options.handleRegister(...args))
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-e4e4508d"]]);
wx.createPage(MiniProgramPage);
